<?php

namespace Syrius\Query;

/**
 * Enter description here ...
 * @package	Query
 * @author	Domenico Biancardi <domenico.biancardi@gmail.com>
 * @link	http://code.google.com/p/syrius/
 *
 */ class Update extends Query {
	/**
	 * I suoi possibili valori sono [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
	 */
	private $_opts;

	/**
	 * nome della tabella
	 */
	private $_tbl_name;

	private $_col_names;

	private $_values;

	/**
	 * Permette di definre una query di INSERT basata su una select
	 */
	private $_select;

	/**
	 * Permette di definre l'espressione da attuare nel caso di inserimento con chiavi duplicate
	 */
	private $_onDuplicate;

	public function __construct($tbl_name = "", $col_names = array(), $values = array(), $whereKey = "", $whereValue = "") {
		$this->_tbl_name = $tbl_name;
		$this->_col_names = $col_names;
		$this->_values = $values;
		$this->_whereKey = $whereKey;
		$this->_whereValue = $whereValue;
	}

	/**
	 * Ritorna la versione stringa dell'oggetto che �stato creato
	 */
	public function __toString() {
		$part = array();
		$whereValue = "";
		foreach ($this->_values as $k => $v) {
			if ($this->_col_names [$k] == $this->_whereKey) {
				$whereValue = $v;
			}
			$part [] = $this->_col_names [$k] . " = " . $v;
		}
		$sql = "UPDATE " . $this->_tbl_name . " SET " . implode(",", $part) . " WHERE " . $this->_whereKey . " = " . $this->_whereValue;
		return $sql;
	}

	private $_whereKey;

}

?>
